/**
 * @author lteng
 * @time 2022-06-18 17:52:22 
 */

package liteng.study.cn.stuscore.service.impl;

import liteng.study.cn.stuscore.dao.ExamDao;
import liteng.study.cn.stuscore.dao.ScoreDao;
import liteng.study.cn.stuscore.dao.StudentDao;
import liteng.study.cn.stuscore.dao.impl.ExamDaoImpl;
import liteng.study.cn.stuscore.dao.impl.ScoreDaoImpl;
import liteng.study.cn.stuscore.dao.impl.StudentDaoImpl;
import liteng.study.cn.stuscore.entity.Score;
import liteng.study.cn.stuscore.service.ScoreService;

/**
 * 学生成绩业务层实现类
 */
public class ScoreServiceImpl implements ScoreService {
	private ScoreDao scoreDao = new ScoreDaoImpl();

	private StudentDao studentDao = new StudentDaoImpl();

	private ExamDao examDao = new ExamDaoImpl();

	@Override
	public void add(Score score) {
		// TODO Auto-generated method stub
		scoreDao.add(score);
	}

	@Override
	public void update(Score score) {
		// TODO Auto-generated method stub
		scoreDao.update(score);
	}

	@Override
	public void delete(Score score) {
		// TODO Auto-generated method stub
		scoreDao.delete(score);
	}

	@Override
	public Score getOne(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void editScore(String[] sIds, String[] scores, int eId) {
		// TODO Auto-generated method stub
		for (int i = 0; i < sIds.length; i++) {
			
			long sId = Long.valueOf(sIds[i]);
			float score = Float.valueOf(scores[i]);

			Score temp = getScore(sId, eId);

			if (temp == null) {

				temp = new Score();
				temp.setEid(eId);
				temp.setSid(sId);
				temp.setScore(score);

				scoreDao.add(temp);
			} else {
				
				temp.setScore(score);

				scoreDao.update(temp);
			}
		}
	}

	@Override
	public Score getScore(long sId, int eId) {
		// TODO Auto-generated method stub
		Score score = scoreDao.qryScore(sId, eId);
		return score;
	}

}
